<template>
  <div class="listl">
    <ul class="details">
      <h2>云音乐特色榜</h2>
      <li v-for="(item, index) in listArr1" :key="index" @click="Go(item)" :class="{ active: item.id == id }">
        <img :src="item.coverImgUrl" alt="" width="40" height="40" />
        <div class="right">
          <span>{{ item.name }}</span>
          <span class="update">{{ item.updateFrequency }}</span>
        </div>
      </li>
    </ul>
    <ul class="details">
      <h2>全球媒体榜</h2>
      <li v-for="(item, index) in listArr2" :key="index" @click="Go(item)" :class="{ active: item.id == id }">
        <img :src="item.coverImgUrl" alt="" width="40" height="40" />
        <div class="right">
          <span>{{ item.name }}</span>
          <span class="update">{{ item.updateFrequency }}</span>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { BdApi } from "@/request/api";
export default {
  data() {
    return {
      listArr: [],
      listArr1: [],
      listArr2: []
    };
  },
  created() {
    BdApi().then((res) => {
      // console.log(res);
      this.listArr = res.data.list;
      this.listArr1 = res.data.list.slice(0, 4);
      this.listArr2 = res.data.list.slice(4);
    });
  },
  methods: {
    Go(item) {
      this.$router.push({
        path: "/discover/toplist",
        query: {
          id: item.id,
          update: item.updateFrequency,
        },
      });
      this.$router.go(0);
    },
  },
  computed: {
    id() {
      if (this.$route.query.id == undefined) return "19723756";
      return this.$route.query.id;
    },
    update() {
      if (this.$route.query.update == undefined) return "刚刚更新";
      return this.$route.query.update;
    }
  },
};
</script>
 
<style lang = "less" scoped>
@import "../../assets/base";
.listl {
  padding-top: 30px;
  width: 260px;
  background-color: #F9F9F9;
  border-right: 1px solid #D7D7D7;
  border-left: 1px solid #D7D7D7;
  h2 {
    font-size: 14px;
    font-family: 'simsun';
    font-weight: bold;
    line-height: 60px;
    height: 60px;
    margin-left: 20px;
  }
  li {
    height: 60px;
    line-height: 30px;
    padding: 10px;
    box-sizing: border-box;
    span {
      margin-left: 20px;
      font-size: 12px;
    }
    img {
      vertical-align: middle;
      margin-left: 10px;
    }
    .right {
      margin-left: 50px;
      margin-top: -55px;
      span {
        display: block;
        height: 20px;
        line-height: 50px;
      }
      .update {
        color: #999;
      }
    }
    cursor: pointer;
    &:hover {
      background: #f4f2f2;
    }
  }
  .active {
    background: #e6e6e6;
  }
}
</style>